
/// 缓存队列, 可一边缓存数据, 一边使用数据, 缓存满时, 自动覆盖最旧的数据
pub struct FixedArray<T, const LEN: usize> {
    count: usize,
    items: [T; LEN],
    pos: usize,
}

impl<T: Default, const LEN: usize> FixedArray<T, LEN> {
    pub fn new() -> Self {
        let items = std::array::from_fn(|_| T::default());
        FixedArray {
            count: 0,
            items: items,
            pos: 0,
        }
    }
}

impl<T, const LEN: usize> FixedArray<T, LEN> {
    pub fn push(&mut self, t: T) {
        self.count += 1;
        self.items[self.pos] = t;
        self.pos += 1;
        if self.pos >= LEN {
            self.pos = 0;
        }
    }
    pub fn count(&self) -> usize {
        self.count
    }
    pub fn items(&self) -> &[T] {
        &self.items
    }
}
